{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "initial_id",
   "metadata": {
    "collapsed": true,
    "ExecuteTime": {
     "end_time": "2024-05-22T09:03:58.256498Z",
     "start_time": "2024-05-22T09:03:49.153618Z"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "42.25\n"
     ]
    }
   ],
   "source": [
    "num = eval(input(\"请输入一个整数\"))\n",
    "print(num ** 2)"
   ]
  },
  {
   "cell_type": "code",
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "9\n"
     ]
    }
   ],
   "source": [
    "try:\n",
    "    num = eval(input(\"请输入一个整数\"))\n",
    "    print(num ** 2)\n",
    "except:\n",
    "    print(\"输入的不是整数\")"
   ],
   "metadata": {
    "collapsed": false,
    "ExecuteTime": {
     "end_time": "2024-05-22T09:21:45.860413Z",
     "start_time": "2024-05-22T09:21:39.796968Z"
    }
   },
   "id": "591fc6b3a4252343",
   "execution_count": 2
  },
  {
   "cell_type": "code",
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "错误: division by zero\n",
      "错误: division by zero\n",
      "错误: division by zero\n",
      "错误: division by zero\n",
      "错误: division by zero\n",
      "错误: division by zero\n",
      "错误: division by zero\n",
      "错误: division by zero\n",
      "错误: division by zero\n",
      "错误: division by zero\n",
      "错误: division by zero\n",
      "错误: division by zero\n",
      "错误: division by zero\n",
      "错误: division by zero\n",
      "错误: division by zero\n",
      "错误: division by zero\n",
      "10.0\n"
     ]
    }
   ],
   "source": [
    "from random import randint\n",
    "\n",
    "sm = 0\n",
    "i = 0\n",
    "while i < 10:\n",
    "    try:\n",
    "        sm = sm + 1 / randint(0, 1)\n",
    "        i = i + 1\n",
    "    except Exception as e:\n",
    "        print(\"错误:\", e)\n",
    "else:\n",
    "    print(sm)"
   ],
   "metadata": {
    "collapsed": false,
    "ExecuteTime": {
     "end_time": "2024-05-22T09:21:56.460599Z",
     "start_time": "2024-05-22T09:21:56.453596Z"
    }
   },
   "id": "3126bcc8f02d8549",
   "execution_count": 3
  },
  {
   "cell_type": "code",
   "outputs": [],
   "source": [
    "# 获取用户输入的成绩\n",
    "score = float(input(\"请输入学生的成绩（0-100）：\"))\n",
    "\n",
    "# 根据成绩判断等级\n",
    "if score >= 90:\n",
    "    grade = '优'\n",
    "elif 90 > score >= 80:\n",
    "    grade = '良'\n",
    "elif 80 > score >= 70:\n",
    "    grade = '中等'\n",
    "elif 70 > score >= 60:\n",
    "    grade = '及格'\n",
    "else:\n",
    "    grade = '不及格'\n",
    "\n",
    "# 输出成绩等级\n",
    "print(f\"学生的成绩等级是：{grade}\")"
   ],
   "metadata": {
    "collapsed": false
   },
   "id": "3826f58e2f310dd5"
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 2
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython2",
   "version": "2.7.6"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
